package com.ssy.lingxi.order.model.vo.mobile.response;

import com.ssy.lingxi.common.constant.order.OrderSourceKindEnum;
import com.ssy.lingxi.common.constant.product.PriceTypeEnum;
import com.ssy.lingxi.order.model.constant.OrderOuterStatusEnum;
import com.ssy.lingxi.order.model.constant.OrderProductDeliverTypeEnum;
import com.ssy.lingxi.order.model.constant.OrderPromotionStatusEnum;
import com.ssy.lingxi.order.model.constant.VendorInnerStatusEnum;
import com.ssy.lingxi.order.utils.NumberUtil;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;

/**
 * 订单详情 - 商品详情
 * @author 万宁
 * @version 2.0.0
 * @date 2021-09-25
 */
public class MobileOrderProductDetailVO implements Serializable {
    private static final long serialVersionUID = 326217792672824312L;

    public MobileOrderProductDetailVO(Integer orderKind, Integer outerStatus, Integer promotionStatus, Boolean hasPaid, Boolean hasDelivered, Long orderProductId, Long productId, Long skuId, Integer priceType, String logo, String name, String category, String brand, String spec, String unit, BigDecimal price, BigDecimal refPrice, BigDecimal quantity, Integer deliverType, String address, String receiver, String phone, BigDecimal taxRate) {
        this.orderProductId = orderProductId;
        this.productId = productId;
        this.skuId = skuId;
        this.priceType = priceType;
        this.logo = logo;
        this.name = name;
        this.category = category;
        this.brand = brand;
        this.spec = spec;
        this.unit = unit;
        this.price = NumberUtil.formatAmount(price);
        this.refPrice = NumberUtil.formatAmount(refPrice);
        this.quantity = NumberUtil.formatToInteger(quantity);
        this.deliverType = deliverType;
        this.deliverTypeName = OrderProductDeliverTypeEnum.getNameByCode(deliverType);
        this.address = address;
        this.receiver = receiver;
        this.phone = phone;
        //如果是拼团订单：当前订单是参与了拼团活动的订单，且拼团状态为拼团失败，且订单的外部状态为“待确认发货”
        //如果非拼团订单：已经有收到款或有发货的订单即显示售后按钮（包括状态为已中止的订单）
        this.showAfterSale = orderKind.equals(OrderSourceKindEnum.GROUP.getCode()) ? (outerStatus.equals(OrderOuterStatusEnum.TO_CONFIRM_DELIVERY.getCode()) && promotionStatus.equals(OrderPromotionStatusEnum.GROUP_FAILED.getCode())) : (hasPaid || hasDelivered);
        this.taxRate = NumberUtil.formatAmount(taxRate);
        this.showModifyPrice = !(PriceTypeEnum.Gift.getCode().equals(priceType) && hasPaid);
    }

    public MobileOrderProductDetailVO(Integer orderKind, Integer innerStatus, Integer outerStatus, Integer promotionStatus, Boolean hasPaid, Boolean hasDelivered, Long orderProductId, Long productId, Long skuId, Integer priceType, String logo, String name, String category, String brand, String spec, String unit, BigDecimal price, BigDecimal refPrice, BigDecimal quantity, Integer deliverType, String address, String receiver, String phone, BigDecimal taxRate) {
        this.orderProductId = orderProductId;
        this.productId = productId;
        this.skuId = skuId;
        this.priceType = priceType;
        this.logo = logo;
        this.name = name;
        this.category = category;
        this.brand = brand;
        this.spec = spec;
        this.unit = unit;
        this.price = NumberUtil.formatAmount(price);
        this.refPrice = NumberUtil.formatAmount(refPrice);
        this.quantity = NumberUtil.formatToInteger(quantity);
        this.deliverType = deliverType;
        this.deliverTypeName = OrderProductDeliverTypeEnum.getNameByCode(deliverType);
        this.address = address;
        this.receiver = receiver;
        this.phone = phone;
        //如果是拼团订单：当前订单是参与了拼团活动的订单，且拼团状态为拼团失败，且订单的外部状态为“待确认发货”
        //如果非拼团订单：已经有收到款或有发货的订单即显示售后按钮（包括状态为已中止的订单）
        this.showAfterSale = orderKind.equals(OrderSourceKindEnum.GROUP.getCode()) ? (outerStatus.equals(OrderOuterStatusEnum.TO_CONFIRM_DELIVERY.getCode()) && promotionStatus.equals(OrderPromotionStatusEnum.GROUP_FAILED.getCode())) : (hasPaid || hasDelivered);
        this.taxRate = NumberUtil.formatAmount(taxRate);
        this.showModifyPrice = VendorInnerStatusEnum.VENDOR_TO_SUBMIT_VALIDATE.getCode().equals(innerStatus) && !(PriceTypeEnum.Gift.getCode().equals(priceType) && hasPaid);
    }

    /**
     * 订单服务生成的，唯一的订单商品Id
     */
    private Long orderProductId;

    /**
     * 商品服务中的商品Id
     */
    private Long productId;

    /**
     * 商品服务中的商品库存Id
     */
    private Long skuId;

    /**
     * 商品价格类型，1-现货价格，2-询价价格，3-积分兑换，4-赠品
     */
    private Integer priceType;

    /**
     * 商品logo
     */
    private String logo;

    /**
     * 商品名称
     */
    private String name;

    /**
     * 商品品类
     */
    private String category;

    /**
     * 商品品牌
     */
    private String brand;

    /**
     * 商品规格
     */
    private String spec;

    /**
     * 计价单位
     */
    private String unit;

    /**
     * 原价，保留到小数点后两位
     */
    private String price;

    /**
     * 单价（到手价），保留到小数点后两位
     */
    private String refPrice;

    /**
     * 采购数量
     */
    private String quantity;

    /**
     * 配送方式，1-物流， 2-自提， 3-无需配送
     */
    private Integer deliverType;

    /**
     * 配送方式名称
     */
    private String deliverTypeName;

    /**
     * 自提地址（如配送方式为自提）
     */
    private String address;

    /**
     * 接收人（如配送方式为自提）
     */
    private String receiver;

    /**
     * 接收人电话（如配送方式为自提）
     */
    private String phone;

    /**
     * 税率（百分比转换的小数）
     */
    private String taxRate;

    /**
     * 是否显示“申请售后”按钮
     */
    private Boolean showAfterSale;

    /**
     * 是否显示“修改单价”按钮
     */
    private Boolean showModifyPrice;

    public Long getOrderProductId() {
        return orderProductId;
    }

    public void setOrderProductId(Long orderProductId) {
        this.orderProductId = orderProductId;
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public Long getSkuId() {
        return skuId;
    }

    public void setSkuId(Long skuId) {
        this.skuId = skuId;
    }

    public Integer getPriceType() {
        return priceType;
    }

    public void setPriceType(Integer priceType) {
        this.priceType = priceType;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getSpec() {
        return spec;
    }

    public void setSpec(String spec) {
        this.spec = spec;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getPrice() { return price; }

    public void setPrice(String price) { this.price = price; }

    public String getRefPrice() {
        return refPrice;
    }

    public void setRefPrice(String refPrice) {
        this.refPrice = refPrice;
    }

    public String getQuantity() {
        return quantity;
    }

    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public Integer getDeliverType() {
        return deliverType;
    }

    public void setDeliverType(Integer deliverType) {
        this.deliverType = deliverType;
    }

    public String getDeliverTypeName() {
        return deliverTypeName;
    }

    public void setDeliverTypeName(String deliverTypeName) {
        this.deliverTypeName = deliverTypeName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getReceiver() {
        return receiver;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getTaxRate() {
        return taxRate;
    }

    public void setTaxRate(String taxRate) {
        this.taxRate = taxRate;
    }

    public Boolean getShowAfterSale() {
        return showAfterSale;
    }

    public void setShowAfterSale(Boolean showAfterSale) {
        this.showAfterSale = showAfterSale;
    }

    public Boolean getShowModifyPrice() {
        return showModifyPrice;
    }

    public void setShowModifyPrice(Boolean showModifyPrice) {
        this.showModifyPrice = showModifyPrice;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        MobileOrderProductDetailVO that = (MobileOrderProductDetailVO) o;
        return Objects.equals(orderProductId, that.orderProductId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(orderProductId);
    }
}
